package com.young.springdemo.controller;

import com.young.springdemo.domain.User;
import com.young.springdemo.mybatis.UserService;
import com.young.springdemo.service.strategy.InspectionSolverChooser;
import com.young.springdemo.service.strategy.InspectorSolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("order")
public class OrderService {

    @Autowired
    private UserService userService;

    @GetMapping(value = "getUser")
    public User getUser(@RequestParam Integer id){
        return userService.getUser(id);
    }

    @PostMapping(value = "delOrder")
    public void delAllOrder(String type) {
        String[] commands;
        if ("ALL".equals(type)) {
            commands = new String[]{"CHANGE_SHIPPING", "CHANGE_WARE_HOUSE", "REPLACE_ORDER_GOODS"};
        } else {
            commands = new String[]{type};
        }
        for (String command : commands) {
            delOrder(command);
        }
    }

    @Autowired
    private InspectionSolverChooser choose;

    public Map delOrder(String type) {
        InspectorSolver chooses = this.choose.choose(type);
        if (null == choose) {
            return null;
        }
        chooses.solve(145555L, 44L);
        return new HashMap();
    }
}
